/**
 * Copyright (c) 2019 xstgongyi.org
 * All rights reserved.
 */
package org.xstgongyi.eduaid.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.xstgongyi.eduaid.dataobject.ProjectDO;
import org.xstgongyi.eduaid.manager.ProjectManager;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @author oldcrane<br />
 * @created 2019-04-03
 */
@Service
public class ProjectServiceImpl implements ProjectService {

    @Autowired
    private ProjectManager projectManager;

    @Override
    public List<ProjectDO> listAll() {
        return projectManager.listAll();
    }

    @Override
    public ProjectDO getById(Integer id) {
        return projectManager.getById(id);
    }

    @Override
    public void insert(String name, String prefix, LocalDate startDate, String description) {
        // TODO 此处需要增加逻辑，检查name是否重复
        // TODO 需要增加异常处理逻辑
        ProjectDO projectDO = new ProjectDO();
        projectDO.setName(name);
        projectDO.setPrefix(prefix);
        projectDO.setStartDate(startDate);
        projectDO.setDescription(description);
        LocalDateTime now = LocalDateTime.now();
        projectDO.setGmtCreated(now);
        projectDO.setGmtUpdated(now);
        projectManager.insert(projectDO);
    }

    @Override
    public void update(Integer id, String name, String prefix, LocalDate startDate, String description) {
        // TODO 此处需要增加逻辑，检查name是否重复
        // TODO 需要增加异常处理逻辑
        ProjectDO projectDO = new ProjectDO();
        projectDO.setId(id);
        projectDO.setName(name);
        projectDO.setPrefix(prefix);
        projectDO.setStartDate(startDate);
        projectDO.setDescription(description);
        projectDO.setGmtUpdated(LocalDateTime.now());
        projectManager.update(projectDO);
    }

}
